import Vue from "vue";
import VueRouter from "vue-router";


Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    name: "index",
    redirect: "/daili",
    component: () => import("@/views/IndexPage"),
    children: [
      {
        path: "/daili",
        name: "daili",
        component: () => import("@/views/DaiLi")
      },
      {
        path: "/message",
        name: "message",
        component: () => import("@/views/Message")
      },
      {
        path: "/news",
        name: "news",
        component: () => import("@/views/News")
      },
    ]
  },
  {
    path: "/login",
    name: "login",
    component: () => import("@/views/UserLogin")
  }

];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes
});


router.beforeEach((to, from, next) => {
  let token = localStorage.miniToken
  let path = to.path
  if (!token && path != "/login") {
    next("/login")
  } else {
    next()
  }
  
})

export default router;
